﻿using System.Device.Location;
using System.Windows;

namespace LocationSampleWPF
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            this.Loaded += (s1, e1) =>
                {
                    _geoCoordinateWatcher = new GeoCoordinateWatcher();
                    _geoCoordinateWatcher.PositionChanged += (s, e) =>
                        {
                            //Dispatcher.BeginInvoke(delegate()
                            //    {
                            _longitude.Text = e.Position.Location.Longitude.ToString();
                            _latitude.Text = e.Position.Location.Latitude.ToString();
                            _altitude.Text = e.Position.Location.Altitude.ToString();
                            _course.Text = e.Position.Location.Course.ToString();
                            //    }, null);
                        };
                    _geoCoordinateWatcher.StatusChanged += (s, e) =>
                        {
                            _status.Text = e.Status.ToString();
                        };
                };
        }

        //~MainWindow()
        //{
        //    //_geoCoordinateWatcher.Stop();
        //}

        GeoCoordinateWatcher _geoCoordinateWatcher;

        private void _on_Click(object sender, RoutedEventArgs e)
        {
            _geoCoordinateWatcher.Start();
        }

        private void _off_Click(object sender, RoutedEventArgs e)
        {
            _geoCoordinateWatcher.Stop();
        }
    }
}
